<?php
/**
 * 热销商品
 *
 * by abc.com 多用户商城
 *
 *
 */
//by abc.com
//use Shopnc\Tpl;

defined('InShopNC') or exit('Access Invalid!');
class good_recommendControl extends mobileHomeControl{

	public function __construct() {
        parent::__construct();
    }

    public function goods_class_listOp(){
    	$g_c_id=$_POST['gc_id'];
    	//获取子分类
    	$goods_class=Model('goods_class');
    	$goods_class->dropCache();
    	$gc_child=$goods_class->getChildClass($g_c_id);
    
    	if(count($gc_child)>1){
    		//有子分类，获取子分类下所有产品的前十
    		//echo json_encode($gc_child);
    		//把id拿出来
    		$i=0;
    		foreach ($gc_child as $key => $value) {
    			# code...
    			$gc_id_list[$i]=$value['gc_id'];
    			$i++;
    		}
    		$gcs=json_encode($gc_id_list);
    		$gcs=str_replace('[','(',$gcs);
    		$gcs=str_replace(']',')',$gcs);
    		//echo $gcs;
    		
    		// $order=Model('order');
    		// $condition['a.gc_id']= array('in',$gc_id_list);
    		// $on = 'a.goods_id=g.goods_id';
    		//$list=$model->table('goods as g,(select count(*) as count,gc_id,goods_id from lxs_order_goods GROUP BY goods_id ORDER BY count desc) as a')->join('inner')->on($on)->where($condition)->limit(10)->select();
    		$gc_string='l.gc_id in'.$gcs;
    		
    	}
    	else{
    		//没有子分类，也就是最后一级，获取该分类下所有产品的前十
    		$gc_string='l.gc_id ='.$g_c_id;
    	}
    	$model=new Model();
    	$string='select count(*) as count,g.*  from lxs_order_goods as l,lxs_goods as g where l.goods_id=g.goods_id and '.$gc_string.' GROUP BY l.goods_id ORDER BY count desc limit 0,10';
    	//echo $string;
    	$list=$model->query($string);
    		
    		output_data(array('goods_list'=>$list));
    }

    public function goods_brand_listOp(){
    	$brand_id=$_POST['brand_id'];
    	
    
    	
    	$model=new Model();
    	$string='select count(*) as count, g.* from lxs_order_goods as l,lxs_goods as g where l.goods_id=g.goods_id and g.brand_id='.$brand_id.' GROUP BY l.goods_id ORDER BY count desc limit 0,10;';
    	//echo $string;
    	$list=$model->query($string);
    		//echo $model->getLastSql();
    		output_data(array('goods_list'=>$list));
    }
}